package com.epam.qanda.web.servlet.logged;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.epam.qanda.db.model.ModeratorCategory;
import com.epam.qanda.db.model.User;
import com.epam.qanda.db.service.ModeratorCategoryService;

public class AccountPageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final Logger LOG = Logger.getLogger("stdout");

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		User user = new User();
		user = (User) session.getAttribute("user");
		List<ModeratorCategory> moderatorCategories = new ModeratorCategoryService()
				.getModeratorCategories(user.getId());
		request.setAttribute("moderatorCategories", moderatorCategories);
		LOG.info("Created list of Moderator Categories. Length: " + moderatorCategories.size());
		request.getRequestDispatcher("WEB-INF/pages/accountPage.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}
